package com.open.trace.controller;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;

/**
 * @author zhang kaichao
 * @since 2021/3/4 20:33:43
 */
@RestController
@RequestMapping("trace")
@Slf4j
@AllArgsConstructor
public class TestTraceController {

    private final ExecutorService executorService;

    @GetMapping("traceLog")
    public String traceLog() {
        log.info("---接口调用了---");
        traceService();
        asyncTrace();
        return "success";
    }

    private void traceService(){
        log.error("## 执行traceService方法");
    }

    private void asyncTrace(){
        CompletableFuture.runAsync(()->{
            log.info("执行线程池中的方法asyncTrace，未重写了线程池");
        }, executorService);
    }

}
